package cn.lyh.gulimall.product.controller;

import cn.lyh.gulimall.product.entity.PmsCategoryBrandRelation;
import cn.lyh.gulimall.product.service.PmsCategoryBrandRelationService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import utils.R;

import java.util.Arrays;
import java.util.List;

/**
 * @author lyh
 * @version 1.0
 * @since 2021/4/13
 */
@RestController
@RequestMapping("/product/categorybrandrelation/")
public class PmsCategoryBrandRelationController {

	@Autowired
	PmsCategoryBrandRelationService categoryBrandRelationService;

	/**
	 * 获取关联列表
	 * @param brandId id
	 * @return 数据和结果
	 */
	@GetMapping("/catelog/list")
	public R list(@RequestParam Long brandId) {
		List<PmsCategoryBrandRelation> list = categoryBrandRelationService
				.list(new QueryWrapper<PmsCategoryBrandRelation>().eq(PmsCategoryBrandRelation.COL_BRAND_ID, brandId));
		return R.ok().put("data",list);
	}

	@PostMapping("/delete")
	public R delete(@RequestBody Long[] id){
		categoryBrandRelationService.removeByIds(Arrays.asList(id));
		return R.ok();
	}

	/**
	 * 保存方法
	 * @param categoryBrandRelation 数据
	 * @return 操作结果
	 */
	@PostMapping("/save")
	public R save(@RequestBody PmsCategoryBrandRelation categoryBrandRelation) {
		categoryBrandRelationService.saveDetail(categoryBrandRelation);
		return R.ok();
	}

}
